package com.kyc.kycxkplaygame.greendao.manager;

import com.kyc.kycxkplaygame.PlayGameApplication;
import com.kyc.kycxkplaygame.greendao.PropInfoBean;
import com.kyc.kycxkplaygame.greendao.gen.PropInfoBeanDao;

import java.util.List;

/**
 * Created by Administrator on 2017/12/21.
 */

public class PropInfoManager {
    public static PropInfoManager mHelp;
    private PropInfoBeanDao mDao;

    public static PropInfoManager getInstance(){
        if(mHelp==null){
            mHelp = new PropInfoManager();
            return mHelp;
        }else {
            return mHelp;
        }
    }

    private PropInfoManager(){
        mDao =  PlayGameApplication.getInstance().getDaoSession().getPropInfoBeanDao();
    }

    public void deleteUserInfo(PropInfoBean entity){
        mDao.delete(entity);
    }

    public void insertPropInfo(PropInfoBean entity){
        //mDao.insertOrReplace(entity);
        mDao.insert(entity);
    }

   /* public void insertPropInfo(List<PropInfoBean> entity){
        for (int i = 0; i < entity.size(); i++) {
            PropInfoBean propInfoBean = entity.get(i);
            PropInfoBean bean = new PropInfoBean();
            bean.setPropName(propInfoBean.getPropName());
            bean.setPropNum(propInfoBean.getPropNum());
            bean.setId(propInfoBean.getId());
            bean.setUserName(propInfoBean.getUserName());
            mDao.insert(bean);
           // mDao.insertOrReplace(bean);
        }
    }*/

    public void insertPropInfo(List<PropInfoBean> entity){
        for (int i = 0; i < entity.size(); i++) {
            PropInfoBean propInfoBean = entity.get(i);
            PropInfoBean bean = new PropInfoBean();
            bean.setPropName(propInfoBean.getPropName());
            bean.setPropNum(propInfoBean.getPropNum());
            bean.setId(propInfoBean.getId());
            bean.setUserName(propInfoBean.getUserName());
            //mDao.insert(bean);
             mDao.insertOrReplace(bean);
        }
    }

    public void updateUserInfo(PropInfoBean entity){
        mDao.update(entity);
    }

    public void updatePropInfo(PropInfoBean entity){
        /*PropInfoBean bean = new PropInfoBean();
        bean.setId(entity.getId());
        bean.setUserName(entity.getUserName());
        bean.setPropNum(entity.getPropNum());
        bean.setPropName(entity.getPropName());*/
        mDao.update(entity);
    }

    public List<PropInfoBean> getPropInfo(){  //page 分页0开始每页15条
        List<PropInfoBean> mlist = mDao.queryBuilder().list();
        return mlist;
    }

    /*public List<UserInfoGdBean> getOperatorInfoUser(int page){  //page 分页0开始每页15条
        List<UserInfoGdBean> mlist = mDao.queryBuilder().where(OperatorInfoBeanDao.Properties.Type.eq(0))
                .orderDesc(OperatorInfoBeanDao.Properties.CreateDate)
                .offset(15*page)
                .limit(20)
                .list();
        return mlist;
    }*/



   /* public List<PropInfoBean> getInfoPropname(String  username){  //page 分页0开始每页15条
        List<PropInfoBean> mlist = mDao.queryBuilder().where(PropInfoBeanDao.Properties.UserName.eq(username)).list();
        return mlist;
    }*/

    public List<PropInfoBean> getInfoPropname(String  propName){  //page 分页0开始每页15条
        List<PropInfoBean> mlist = mDao.queryBuilder().where(PropInfoBeanDao.Properties.PropName.eq(propName)).list();
        return mlist;
    }

   /* public int getUserInfoCount(){  //page 分页0开始每页10条
        List<PropInfoBean> mlist = mDao.queryBuilder().list();
        int count = (mlist.size() - 1) / 20 + 1;
        return count;
    }*/

    public int getPropInfoCount(){  //page 分页0开始每页10条
        List<PropInfoBean> mlist = mDao.queryBuilder().list();
        return mlist.size();
    }


    /*public List<GuestRegistrationBean> getLobbyCompany(String name,String sex){  //page 分页0开始每页15条
        List<GuestRegistrationBean> mlist = mDao.queryBuilder()
                .where(GuestRegistrationBeanDao.Properties.Username.eq(name),
                        GuestRegistrationBeanDao.Properties.Gender.eq(sex))
                .orderDesc(GuestRegistrationBeanDao.Properties.CreateDate).list(); //.orderDesc(VisitorMsgEntityDao.Properties.Start_time).list();
        List<GuestRegistrationBean> mData = new ArrayList<>();
        if(mlist != null && mlist.size() > 0) {
            for (GuestRegistrationBean visit:mlist) {
                String createAt = visit.getCreateDate();
                Date date1 = DateUtil.stringToDate(createAt, "yyyy-MM-dd");
                //long aLong = Long.parseLong(createAt);
                long timeMillis = System.currentTimeMillis();
                Date date = DateUtil.longToDate(timeMillis, "yyyy-MM-dd");
                int i = date1.compareTo(date);
                if(i <= 0){
                    mData.add(visit);
                }
            }
        }
        return mData;
    }*/


}
